﻿using EasyCore.DataValidation;
using EasyCore.DependencyInjection;
using EasyCore.Domain.Services;
using EasyCore.Entities;
using EasyCore.Modules;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyCore
{
    internal class EasyCoreModule:EasyModule
    {
        public EasyCoreModule(IServiceCollection services) : base(services)
        {
        }

        public override void ConfigureServices()
        {
            //注册系统中用的的依赖注册的所有类
            Services.AddTypes(); 
                                 
            
            // 启用了全局验证，则默认关闭原生 ModelStateInvalidFilter 验证
            Services.Configure<ApiBehaviorOptions>(options =>
            {
                options.SuppressMapClientErrors = true;//禁用错误映射
                options.SuppressModelStateInvalidFilter = true; //true:禁用默认行为
            });
            Services.Configure<MvcOptions>(options =>
            {
                options.Filters.Add<DataValidationFilter>(); //参数验证
            });
        }
    }
}
